import Mock from 'mockjs2'
import { builder } from '../util'

const totalCount = 5701

const serverList = () => {
  const result = []
  const pageNo = 0
  const pageSize = 15
  const totalPage = Math.ceil(totalCount / pageSize)
  const key = (pageNo - 1) * pageSize
  const next = (pageNo >= totalPage ? (totalCount % pageSize) : pageSize) + 1

  for (let i = 1; i < next; i++) {
    const tmpKey = key + i
    if (i % 2 === 0) {
      result.push({
        key: tmpKey,
        id: tmpKey,
        source: '推广',
        type: '商标',
        customer_name: '徐瑞瑶' + tmpKey,
        tm_name: '天猫' + tmpKey,
        customer_status: '新领取',
        phone: '15050835601',
        district: '南京是，江宁区',
        industry: '广告',
        received_at: Mock.mock('@datetime'),
        created_at: Mock.mock('@datetime')
      })
    } else if (i % 3 === 0) {
      result.push({
        key: tmpKey,
        id: tmpKey,
        source: '黄页',
        type: '专利',
        customer_name: '马婷婷' + tmpKey,
        tm_name: '天猫' + tmpKey,
        customer_status: '空号',
        phone: '15050835601',
        district: '北京市，海淀区',
        industry: '食品加工',
        received_at: Mock.mock('@datetime'),
        created_at: Mock.mock('@datetime')
      })
    } else {
      result.push({
        key: tmpKey,
        id: tmpKey,
        source: '400',
        type: '版权',
        customer_name: '芦传龙' + tmpKey,
        tm_name: '天猫' + tmpKey,
        customer_status: '误点',
        phone: '15050835601',
        district: '徐州市，鼓楼区',
        industry: '餐饮',
        received_at: Mock.mock('@datetime'),
        created_at: Mock.mock('@datetime')
      })
    }
  }

  return builder({
    pageSize: pageSize,
    pageNo: pageNo,
    totalCount: totalCount,
    totalPage: totalPage,
    data: result
  })
}

const paidList = () => {
  const result = []
  const pageNo = 0
  const pageSize = 30
  const totalPage = Math.ceil(totalCount / pageSize)
  const key = (pageNo - 1) * pageSize
  const next = (pageNo >= totalPage ? (totalCount % pageSize) : pageSize) + 1

  for (let i = 1; i < next; i++) {
    const tmpKey = key + i
    result.push({
      key: tmpKey,
      id: tmpKey,
      customer_name: '马婷婷' + tmpKey,
      phone: '15050835601',
      all_money: '4500.00',
      contract: '10',
      business: '10',
      received_at: Mock.mock('@datetime'),
      pay_at: Mock.mock('@datetime')
    })
  }

  return builder({
    pageSize: pageSize,
    pageNo: pageNo,
    totalCount: totalCount,
    totalPage: totalPage,
    data: result
  })
}

// 业务更新
const contractList = () => {
  const result = []
  const pageNo = 0
  const pageSize = 30
  const totalPage = Math.ceil(totalCount / pageSize)
  const key = (pageNo - 1) * pageSize
  const next = (pageNo >= totalPage ? (totalCount % pageSize) : pageSize) + 1

  for (let i = 1; i < next; i++) {
    const tmpKey = key + i
    result.push({
      id: tmpKey,
      key: tmpKey,
      customer_name: '徐瑞瑶',
      phone: '15050835601',
      contract_no: 'HT202003193VUEB1',
      business_type: '-',
      tm_name: '-',
      status: '-'
    })
  }

  return builder({
    pageSize: pageSize,
    pageNo: pageNo,
    totalCount: totalCount,
    totalPage: totalPage,
    data: result
  })
}

//
const businessList = () => {
  const result = []
  const pageNo = 0
  const pageSize = 4
  const totalPage = Math.ceil(totalCount / pageSize)
  const key = (pageNo - 1) * pageSize
  const next = (pageNo >= totalPage ? (totalCount % pageSize) : pageSize) + 1

  for (let i = 1; i < next; i++) {
    const tmpKey = key + i
    result.push({
      id: tmpKey,
      key: tmpKey,
      business_no: 'YW202003193VUEB1',
      tm_name: '天猫',
      business_type: '商标转让',
      phone: '15050835601',
      business_status: '形式审查'
    })
  }

  return builder({
    pageSize: pageSize,
    pageNo: pageNo,
    totalCount: 5,
    totalPage: 1,
    data: result
  })
}

Mock.mock(/\/unpay/, 'get', serverList)
Mock.mock(/\/paid/, 'get', paidList)
Mock.mock(/\/business/, 'get', businessList)
Mock.mock(/\/contract/, 'get', contractList)
